package com.wuyoucar.controller;

import com.wuyoucar.common.ResultBean;
import com.wuyoucar.entity.TUser;
import com.wuyoucar.service.ITUserService;
import com.wuyoucar.service.ITUserinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class LoginAndRegistController {

    @Autowired
    private ITUserService itUserService;
    @Autowired
    private ITUserinfoService itUserinfoService;

    //使用用户名和密码进行登录
    @PostMapping("/loginByName")
    public ResultBean getUser(@RequestBody TUser tUser){
        return itUserService.getUser(tUser);
    }


    //使用手机号进行登录
    @RequestMapping("/loginByCode")
    public ResultBean loginByCode( String usertel, String code){
        System.out.println(usertel);
        return itUserService.getUserByTel(usertel,code);
    }

    //使用手机进行注册
    @RequestMapping("/registByPhone")
    public ResultBean registByPhone(String usertel,String code){
        return itUserService.addUserByTel(usertel,code);
    }

    //获取手机注册验证码
    @RequestMapping("/getCode/{usertel}")
    public ResultBean getCode(@PathVariable("usertel") String usertel){
        return itUserService.getCode(usertel);
    }

    //获取手机登录验证码
    @RequestMapping("/loginCode/{usertel}")
    public ResultBean loginCode(@PathVariable("usertel")String usertel){
        return itUserService.loginCode(usertel);
    }
    //使用用户名密码注册
    @GetMapping("registByName/{username}/{password1}/{password2}")
    public ResultBean registByName(@PathVariable("username")String username,
                                   @PathVariable("password1")String password1,
                                   @PathVariable("password2")String password2){
        return itUserService.addUserByName(username,password1,password2);
    }



}
